package c.a.a.z.b;

import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.RadialGradient;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Shader.TileMode;
import b.f.e;
import c.a.a.b0.k.c;
import c.a.a.b0.k.d;
import c.a.a.b0.k.f;
import c.a.a.l;
import c.a.a.q;
import c.a.a.z.c.a;
import c.a.a.z.c.a.b;
import c.a.a.z.c.p;
import com.pgl.sys.ces.out.ISdkLite;
import java.util.ArrayList;
import java.util.List;

/* compiled from: GradientFillContent */
public class h implements e, b, k {
    public final String a;
    public final boolean b;
    public final c.a.a.b0.l.b c;
    public final e<LinearGradient> d = new e(10);
    public final e<RadialGradient> e = new e(10);
    public final Path f;
    public final Paint g;
    public final RectF h;
    public final List<m> i;
    public final f j;
    public final a<c, c> k;
    public final a<Integer, Integer> l;
    public final a<PointF, PointF> m;
    public final a<PointF, PointF> n;
    public a<ColorFilter, ColorFilter> o;
    public p p;
    public final l q;
    public final int r;

    public h(l lVar, c.a.a.b0.l.b bVar, d dVar) {
        Path path = new Path();
        this.f = path;
        this.g = new c.a.a.z.a(1);
        this.h = new RectF();
        this.i = new ArrayList();
        this.c = bVar;
        this.a = dVar.g;
        this.b = dVar.h;
        this.q = lVar;
        this.j = dVar.a;
        path.setFillType(dVar.b);
        this.r = (int) (lVar.b.b() / 32.0f);
        a a = dVar.c.a();
        this.k = a;
        a.a.add(this);
        bVar.e(a);
        a = dVar.d.a();
        this.l = a;
        a.a.add(this);
        bVar.e(a);
        a = dVar.e.a();
        this.m = a;
        a.a.add(this);
        bVar.e(a);
        a = dVar.f.a();
        this.n = a;
        a.a.add(this);
        bVar.e(a);
    }

    public String a() {
        return this.a;
    }

    public void b(RectF rectF, Matrix matrix, boolean z) {
        this.f.reset();
        for (int i = 0; i < this.i.size(); i++) {
            this.f.addPath(((m) this.i.get(i)).h(), matrix);
        }
        this.f.computeBounds(rectF, false);
        rectF.set(rectF.left - 1.0f, rectF.top - 1.0f, rectF.right + 1.0f, rectF.bottom + 1.0f);
    }

    public void c() {
        this.q.invalidateSelf();
    }

    public void d(List<c> list, List<c> list2) {
        for (int i = 0; i < list2.size(); i++) {
            c cVar = (c) list2.get(i);
            if (cVar instanceof m) {
                this.i.add((m) cVar);
            }
        }
    }

    public final int[] e(int[] iArr) {
        p pVar = this.p;
        if (pVar != null) {
            Integer[] numArr = (Integer[]) pVar.e();
            int i = 0;
            if (iArr.length == numArr.length) {
                while (i < iArr.length) {
                    iArr[i] = numArr[i].intValue();
                    i++;
                }
            } else {
                iArr = new int[numArr.length];
                while (i < numArr.length) {
                    iArr[i] = numArr[i].intValue();
                    i++;
                }
            }
        }
        return iArr;
    }

    public void f(c.a.a.b0.e eVar, int i, List<c.a.a.b0.e> list, c.a.a.b0.e eVar2) {
        c.a.a.e0.f.f(eVar, i, list, eVar2, this);
    }

    public void g(Canvas canvas, Matrix matrix, int i) {
        Matrix matrix2 = matrix;
        if (!this.b) {
            Shader shader;
            this.f.reset();
            for (int i2 = 0; i2 < this.i.size(); i2++) {
                this.f.addPath(((m) this.i.get(i2)).h(), matrix2);
            }
            this.f.computeBounds(this.h, false);
            long j;
            PointF pointF;
            PointF pointF2;
            c cVar;
            Shader linearGradient;
            if (this.j == f.LINEAR) {
                j = (long) j();
                shader = (LinearGradient) this.d.e(j);
                if (shader == null) {
                    pointF = (PointF) this.m.e();
                    pointF2 = (PointF) this.n.e();
                    cVar = (c) this.k.e();
                    linearGradient = new LinearGradient(pointF.x, pointF.y, pointF2.x, pointF2.y, e(cVar.b), cVar.a, TileMode.CLAMP);
                    this.d.h(j, linearGradient);
                    shader = linearGradient;
                }
            } else {
                j = (long) j();
                shader = (RadialGradient) this.e.e(j);
                if (shader == null) {
                    pointF = (PointF) this.m.e();
                    pointF2 = (PointF) this.n.e();
                    cVar = (c) this.k.e();
                    int[] e = e(cVar.b);
                    float[] fArr = cVar.a;
                    float f = pointF.x;
                    float f2 = pointF.y;
                    float hypot = (float) Math.hypot((double) (pointF2.x - f), (double) (pointF2.y - f2));
                    linearGradient = new RadialGradient(f, f2, hypot <= 0.0f ? 0.001f : hypot, e, fArr, TileMode.CLAMP);
                    this.e.h(j, linearGradient);
                }
            }
            shader.setLocalMatrix(matrix2);
            this.g.setShader(shader);
            a aVar = this.o;
            if (aVar != null) {
                this.g.setColorFilter((ColorFilter) aVar.e());
            }
            this.g.setAlpha(c.a.a.e0.f.c((int) ((((((float) i) / 255.0f) * ((float) ((Integer) this.l.e()).intValue())) / 100.0f) * 255.0f), 0, ISdkLite.REGION_UNSET));
            canvas.drawPath(this.f, this.g);
            c.a.a.c.a("GradientFillContent#draw");
        }
    }

    public <T> void i(T t, c.a.a.f0.c<T> cVar) {
        a aVar;
        p pVar;
        if (t == q.d) {
            aVar = this.l;
            c.a.a.f0.c cVar2 = aVar.e;
            aVar.e = cVar;
        } else if (t == q.C) {
            aVar = this.o;
            if (aVar != null) {
                this.c.u.remove(aVar);
            }
            if (cVar == null) {
                this.o = null;
                return;
            }
            pVar = new p(cVar, null);
            this.o = pVar;
            pVar.a.add(this);
            this.c.e(this.o);
        } else if (t == q.D) {
            pVar = this.p;
            if (pVar != null) {
                this.c.u.remove(pVar);
            }
            if (cVar == null) {
                this.p = null;
                return;
            }
            this.d.b();
            this.e.b();
            pVar = new p(cVar, null);
            this.p = pVar;
            pVar.a.add(this);
            this.c.e(this.p);
        }
    }

    public final int j() {
        int round = Math.round(this.m.d * ((float) this.r));
        int round2 = Math.round(this.n.d * ((float) this.r));
        int round3 = Math.round(this.k.d * ((float) this.r));
        int i = 17;
        if (round != 0) {
            i = 527 * round;
        }
        if (round2 != 0) {
            i = (i * 31) * round2;
        }
        return round3 != 0 ? (i * 31) * round3 : i;
    }
}
